﻿<Page x:Class="MyProject.Views.UserList.UserList"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:MyProject.Views.UserList"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="800">
    <Page.Resources>
        <Style TargetType="DatePickerTextBox">
            <Setter Property="IsReadOnly" Value="True"/>
        </Style>
    </Page.Resources>
    <Grid ShowGridLines="False"
         
          HorizontalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition MinHeight="40"></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <DataGrid
            SelectionMode="Single"
            x:Name="UserDataGrid"
            
            CanUserDeleteRows="False"
            CanUserAddRows="False"
                        
            Grid.Row="1"
            AutoGenerateColumns="False"
            ItemsSource="{Binding dataSource}" 
            Grid.ColumnSpan="10"
            Grid.RowSpan="9">
            <!--
            <DataGrid.Columns>
                <DataGridTextColumn
                    IsReadOnly="True"
                    Header="ID" Binding="{Binding Path=id}">
                </DataGridTextColumn>
                <DataGridTextColumn
                    Header="Имя" Binding="{Binding Path=name}">
                </DataGridTextColumn>
                <DataGridTextColumn
                    Header="Фамилия" Binding="{Binding Path=surname}">
                </DataGridTextColumn>
                <DataGridTextColumn
                    Header="Отчество" Binding="{Binding Path=patronymic}">
                </DataGridTextColumn>
                <DataGridTextColumn
                    IsReadOnly="True"
                    Header="Код" 
                    Binding="{Binding Path=kod}">
                </DataGridTextColumn>
                <DataGridTemplateColumn
                    Header="Дата рождения" SortMemberPath="Date">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <DatePicker
                                
                                Name="date_birth"
            
                                SelectedDateChanged="SelectionChanged"
                                SelectedDate="{Binding Path=date_birth,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                                <DatePicker.Resources>
                                    <Style TargetType="DatePickerTextBox">
                                        <Setter Property="  " Value="True"/>
                                    </Style>
                                </DatePicker.Resources>
                            </DatePicker>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn
                    Header="ИНН" 
                    Binding="{Binding Path=inn}">
                </DataGridTextColumn>
                <DataGridTextColumn
                    Header="ИФНС"
                    Binding="{Binding Path=ifns}">
                </DataGridTextColumn>
                <DataGridTextColumn
                    Header="№ Страхового свидетельства"
                    Binding="{Binding Path=insurance}">
                </DataGridTextColumn>
                <DataGridTextColumn
                    Header="Место рождения"
                    Binding="{Binding Path=place_birth}">
                </DataGridTextColumn>
                <DataGridTemplateColumn Header= "Пол">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox Name="gender_id" SelectionChanged="SelectionChanged">
                                <ComboBox.Style>
                                    <Style TargetType="ComboBox">
                                        <Setter Property="ItemsSource" Value="{Binding DataContext.lists.GenderList, RelativeSource={RelativeSource AncestorType={x:Type Page}}}" />
                                        <Setter Property="SelectedValue" Value="{Binding gender_id, Mode=TwoWay}" />
                                        <Setter Property="IsEditable" Value="True" />
                                        <Setter Property="SelectedValuePath" Value="id" />
                                        <Setter Property="MinWidth" Value="100" />
                                    </Style>
                                </ComboBox.Style>
                            </ComboBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header= "Группа физ. лиц">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox Name="individual_id" SelectionChanged="SelectionChanged">
                                <ComboBox.Style>
                                    <Style TargetType="ComboBox">
                                        <Setter Property="ItemsSource" Value="{Binding DataContext.lists.IndividualList, RelativeSource={RelativeSource AncestorType={x:Type Page}}}" />
                                        <Setter Property="SelectedValue" Value="{Binding individual_id, Mode=TwoWay}" />
                                        <Setter Property="IsEditable" Value="True" />
                                        <Setter Property="SelectedValuePath" Value="id" />
                                        <Setter Property="MinWidth" Value="180" />
                                    </Style>
                                </ComboBox.Style>
                            </ComboBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header= "Документ удостоверяющий личность">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox Name="identity_doc_id" SelectionChanged="SelectionChanged">
                                <ComboBox.Style>
                                    <Style TargetType="ComboBox">
                                        <Setter Property="ItemsSource" Value="{Binding DataContext.lists.IdentityDocList, RelativeSource={RelativeSource AncestorType={x:Type Page}}}" />
                                        <Setter Property="SelectedValue" Value="{Binding identity_doc_id, Mode=TwoWay}" />
                                        <Setter Property="IsEditable" Value="True" />
                                        <Setter Property="SelectedValuePath" Value="id" />
                                        <Setter Property="MinWidth" Value="180" />
                                    </Style>
                                </ComboBox.Style>
                            </ComboBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
            -->
        </DataGrid>
        <StackPanel 
            Grid.Row="0" 
            Grid.Column="0"
            Grid.RowSpan="1"
            Grid.ColumnSpan="10"
            Orientation="Horizontal"
            MinHeight="30">
            <Button 
                x:Name="Mb_Add"
                HorizontalAlignment="Left"
                Command="{Binding InputCommand}"
                CommandParameter="addUser"
                VerticalAlignment="Top"
                Width="85"
                Height="25"
                Margin="8,7,0,0">
                <Button.Resources>
                    <Style TargetType="Border">
                        <Setter Property="CornerRadius" Value="4"/>
                    </Style>
                </Button.Resources>
                <StackPanel Orientation="Horizontal">
                    <Image Height="20" Source="/assets/icons/plus-small.png"/>
                    <TextBlock Margin="0,1,0,0" ><Run Text="Добавить"/></TextBlock>
                </StackPanel>
            </Button>
            <Button
                x:Name="Mb_Menu"
                HorizontalAlignment="Center" 
                VerticalAlignment="Top" 
                Height="25" 
                Width="24"
                Margin="10,7,0,0">
                <Button.Resources>
                    <Style TargetType="Border">
                        <Setter Property="CornerRadius" Value="4"/>
                    </Style>
                </Button.Resources>
                <StackPanel Orientation="Horizontal">
                    <Image 
                        Height="13" 
                        Source="/assets/icons/menu-dots-vertical.png" />
                </StackPanel>
                <Button.ContextMenu>
                    <ContextMenu>
                        <MenuItem
                            CommandParameter="editUser"
                            Header="Редактировать">
                            <MenuItem.Icon>
                                <Image
                                    Height="15" 
                                    Source="/assets/icons/edit.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem
                                CommandParameter="exportUsers"
                                Header="Экспортировать">
                            <MenuItem.Icon>
                                <Image
                                    Height="15"
                                    Width="15"
                                    Source="/assets/icons/export.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem
                                CommandParameter="showChart"
                                Header="Построить график">
                            <MenuItem.Icon>
                                <Image 
                                    Source="/assets/icons/pie-chart.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem
                                CommandParameter="deleteUser"
                                Header="Удалить">
                            <MenuItem.Icon>
                                <Image 
                                    Height="15" 
                                    Source="/assets/icons/delete.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                    </ContextMenu>
                </Button.ContextMenu>
            </Button>
        </StackPanel>
        
    </Grid>
</Page>
